package com.moon.mybatisplus.config;

import com.zaxxer.hikari.HikariDataSource;
import org.springframework.boot.autoconfigure.jdbc.DataSourceProperties;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.boot.jdbc.DataSourceBuilder;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Primary;

import javax.sql.DataSource;

/**
 * @author ：xxx
 * @description：TODO
 * @date ：2024/05/07 9:37
 */
@Configuration
public class DataSourceConfig {

    @Primary
    @Bean(name = "masterDataSource")
    @ConfigurationProperties(prefix = "spring.datasource.master")
    public DataSource masterDataSource() {
        return DataSourceBuilder.create().build();
//        return dataSource;
//        return new HikariDataSource();
//        return DataSourceBuilder.create(properties.getClassLoader())
//                .type(HikariDataSource.class)
//                .driverClassName("com.mysql.cj.jdbc.Driver")
//                .url("jdbc:mysql://rm-2vccu69aa441ozivnfo.mysql.cn-chengdu.rds.aliyuncs.com:3306/yrpay?useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=true&serverTimezone=GMT%2B8&allowMultiQueries=true")
//                .username("root")
//                .password("xQryITq4")
//                .build();

    }

    @Bean(name = "slaveDataSource")
    @ConfigurationProperties(prefix = "spring.datasource.slave")
    public DataSource slaveDataSource() {
        return DataSourceBuilder.create().build();
//        return new HikariDataSource();
//        return DataSourceBuilder.create(properties.getClassLoader())
//                .type(HikariDataSource.class)
//                .driverClassName("com.mysql.cj.jdbc.Driver")
//                .url("jdbc:mysql://rm-2vccu69aa441ozivnfo.mysql.cn-chengdu.rds.aliyuncs.com:3306/test_exercise?useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=true&serverTimezone=GMT%2B8&allowMultiQueries=true")
//                .username("root")
//                .password("xQryITq4")
//                .build();
    }
}
